
import { BasicUrl } from "./request.js"


// export const add = () => {}
// export 函数表达式

export const checkUser = () => {
    
    const baseUrl = BasicUrl;
	// const baseUrl = 'http://120.24.182.152:5000/'
    const Authorization = uni.getStorageSync('keys') || 'null'
    const userinfo = uni.getStorageSync('userinfo') || 'null'
    if(userinfo === 'null'){
        uni.navigateTo({
            url:'/pages/login/login'
        })
        return
    }
    let header = {Authorization}
    return new Promise((resolve,reject)=>{
        uni.request({
          url:  baseUrl + 'check_user/' + userinfo.id + '/',
          header: header,
		  method:'GET',
          success:(res)=>{
            if(res.id){
                if(res.id == userinfo.id){
                    uni.setStorageSync('userinfo', res)
                    resolve(res)
                }else{
                    uni.navigateTo({
                      url: '/pages/login/login',
                    })
                }
            }else{
                uni.navigateTo({
                  url: '/pages/login/login',
                })
            }
           
          },
          fail:(err)=>{
            
           reject(err)
          }
        })
    })
}

